package com.xmy.cultivate.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xmy.cultivate.entity.ServiceFeedback;
import com.xmy.cultivate.service.IServiceFeedbackService;
import com.xmy.cultivate.util.Code;
import com.xmy.cultivate.util.PageResult;
import com.xmy.cultivate.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 服务反馈 前端控制器
 * </p>
 *
 * @author hpiggy
 * @since 2023-10-28
 */
@RestController
@RequestMapping("/api/serviceFeedback")
public class ServiceFeedbackController {

    @Autowired
    @Lazy
    IServiceFeedbackService iServiceFeedbackService;

    @GetMapping()
    public Result findAll(@RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
                          @RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize,
                          @RequestParam(value = "yearPart",required = true) Integer yearPart,
                          @RequestParam(value = "quarterNum",required = true) Integer quarterNum,
                          @RequestParam(value = "schoolId",required = false) Long schoolId,
                          @RequestParam(value = "yearClassId",required = false) Integer yearClassId,
                          @RequestParam(value = "subjectsId",required = false) Long subjectsId,
                          @RequestParam(value = "gradeId",required = false) Long gradeId,
                          @RequestParam(value = "teacherId",required = false) Long teacherId,
                          @RequestParam(value = "lessonNum",required = false) Integer lessonNum,
                          @RequestParam(value = "studentName",required = false) String studentName){
        IPage<ServiceFeedback> iPage = new Page<>(pageNum,pageSize);
        Integer lessonType = 1;
        iServiceFeedbackService.getFeedBadckList(iPage,yearPart,quarterNum,schoolId,yearClassId,teacherId,gradeId,subjectsId,lessonNum,studentName,null);
        return new Result(Code.OK,new PageResult(iPage.getRecords(),iPage.getTotal(),iPage.getPages()));
    }

    @GetMapping("/getFeedBackOne/{id}")
    public Result getFeedBackOne(@PathVariable(value = "id") Long id){
        ServiceFeedback serviceFeedback = iServiceFeedbackService.getFeedBackOne(id);
        return new Result(Code.OK,serviceFeedback,"");
    }

    @PutMapping()
    public Result update(@RequestBody ServiceFeedback serviceFeedback){
        Result result = iServiceFeedbackService.updateOne(serviceFeedback);
        return result;
    }

}
